<?php

require_once(dirname(__FILE__)."/../Loader.php");

function __autoload($classname)
{
	return Daedalus_Loader::load($classname);
}

$errorLevel = 0;
$defaults = array(	"Path"=>"../../Project/");


function check($string)
{
	global $errorLevel;
	global $defaults;
	if(!isset($_GET[$string]))
	{
		echo "Variable \"$string\" is not set on GET, please correct and retry.<br/>";
		$errorLevel++;
		return $defaults[$string];
	} else
		return $_GET[$string];
}

$path = check("Path");

if($errorLevel != 0)
{
	echo '<form>';
	echo 'Path: <input type="text" name="Path" Value="'.$path.'" /><br/>';
	echo '<input type="submit" value="Submit" />';
	echo '</form>';	
} else {
	$dot = new DotGenerator($path);
	$dotFileString = $dot->generateDotString();
	file_put_contents('temp.dot', $dotFileString);
	$dirname = dirname(__FILE__);
	$command = '"'.Config::get('graph', 'path')."dot.exe\" -Tpng {$dirname}/temp.dot  -o {$dirname}/temp.png";
	//var_dump($command);
	shell_exec($command);
	echo <<<HEREDOC
<script type="text/javascript">
	function toggle(name)
	{
		var obj = document.getElementById(name);
		
		if(obj.style.display == 'none')
			obj.style.display = '';
		else
			obj.style.display = 'none';
	}
	
</script>

<img src="temp.png" onclick="toggle('dotFile');" />
<pre id="dotFile" style="display: none;">{$dotFileString}</pre>
HEREDOC;
	
	echo 'Complete.<br/>';
}


?>